package com.moyun.common.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moyun.model.po.system.SysUserEntity;
import com.moyun.service.system.SysUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

/**
 * <h3>moyun-base</h3>
 * <p>自定义的定时任务模板类</p>
 *
 * @author : ybx
 * @date : 2021-09-27 18:09:55
 **/
@Slf4j
@Component
@RequiredArgsConstructor
public class JobTemplate extends QuartzJobBean {

    private final SysUserService sysUserService;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        // 实现业务逻辑 这里是解封账户
        JobDetail jobDetail = context.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();
        String username = (String)jobDataMap.get("username");
        SysUserEntity user = new SysUserEntity();
        user.setEnable(0);
        this.sysUserService.update(user, new QueryWrapper<SysUserEntity>().eq("user_name", username));
        log.info("用户名为:{#{}} 系统用户,账户已经解封",username);
    }
}
